// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.commands.serverCommands;

import java.util.ArrayList;
import zombie.commands.CommandArgs;
import zombie.commands.CommandBase;
import zombie.commands.CommandHelp;
import zombie.commands.CommandName;
import zombie.commands.RequiredRight;
import zombie.core.Translator;
import zombie.core.raknet.UdpConnection;
import zombie.core.znet.ZNet;
import zombie.debug.DebugLog;
import zombie.debug.DebugType;
import zombie.debug.LogSeverity;

@CommandName(
    name = "log"
)
@CommandArgs(
    required = {"(.+)", "(.+)"}
)
@CommandHelp(
    helpText = "UI_ServerOptionDesc_SetLogLevel"
)
@RequiredRight(
    requiredRights = 32
)
public class LogCommand extends CommandBase {
    public LogCommand(String username, String userAccessLevel, String command, UdpConnection connection) {
        super(username, userAccessLevel, command, connection);
    }

    public static DebugType getDebugType(String debugType) {
        ArrayList arrayList = new ArrayList();

        for (DebugType _debugType : DebugType.values()) {
            if (_debugType.name().toLowerCase().startsWith(debugType.toLowerCase())) {
                arrayList.add(_debugType);
            }
        }

        return arrayList.size() == 1 ? (DebugType)arrayList.get(0) : null;
    }

    public static LogSeverity getLogSeverity(String logSeverity) {
        ArrayList arrayList = new ArrayList();

        for (LogSeverity _logSeverity : LogSeverity.values()) {
            if (_logSeverity.name().toLowerCase().startsWith(logSeverity.toLowerCase())) {
                arrayList.add(_logSeverity);
            }
        }

        return arrayList.size() == 1 ? (LogSeverity)arrayList.get(0) : null;
    }

    @Override
    protected String Command() {
        DebugType debugType = getDebugType(this.getCommandArg(Integer.valueOf(0)));
        LogSeverity logSeverity = getLogSeverity(this.getCommandArg(Integer.valueOf(1)));
        if (debugType != null && logSeverity != null) {
            DebugLog.enableLog(debugType, logSeverity);
            if (DebugType.Network.equals(debugType)) {
                ZNet.SetLogLevel(logSeverity);
            }

            return String.format("Server \"%s\" log level is \"%s\"", debugType.name().toLowerCase(), logSeverity.name().toLowerCase());
        } else {
            return Translator.getText(
                "UI_ServerOptionDesc_SetLogLevel",
                debugType == null ? "\"type\"" : debugType.name().toLowerCase(),
                logSeverity == null ? "\"severity\"" : logSeverity.name().toLowerCase()
            );
        }
    }
}
